package com.dynamixsoftware.printershare.smb;

import com.dynamixsoftware.printershare.App;
import com.dynamixsoftware.printershare.smb.netbios.NbtAddress;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Vector;

class UniAddress
{
  private static final int RESOLVER_BCAST = 1;
  private static final int RESOLVER_DNS = 2;
  private static final int RESOLVER_WINS;
  private static int[] resolveOrder;
  private Object addr;
  private String calledName;
  
  static
  {
    if (NbtAddress.getWINSAddress() == null)
    {
      resolveOrder = new int[2];
      resolveOrder[0] = 1;
      resolveOrder[1] = 2;
      return;
    }
    resolveOrder = new int[3];
    resolveOrder[0] = 1;
    resolveOrder[1] = 0;
    resolveOrder[2] = 2;
  }
  
  private UniAddress(Object paramObject)
  {
    if (paramObject == null) {
      throw new IllegalArgumentException();
    }
    this.addr = paramObject;
  }
  
  static UniAddress[] getAllByName(String paramString, boolean paramBoolean)
    throws UnknownHostException
  {
    if ((paramString == null) || (paramString.length() == 0)) {
      throw new UnknownHostException();
    }
    UniAddress[] arrayOfUniAddress1;
    if (isDotQuadIP(paramString))
    {
      arrayOfUniAddress1 = new UniAddress[1];
      arrayOfUniAddress1[0] = new UniAddress(NbtAddress.getByName(paramString));
    }
    int i;
    Object localObject1;
    Object localObject2;
    for (;;)
    {
      return arrayOfUniAddress1;
      i = 0;
      localObject1 = null;
      if (i < resolveOrder.length) {}
      try
      {
        switch (resolveOrder[i])
        {
        default: 
          throw new UnknownHostException(paramString);
        case 0: 
          if ((paramString != "\001\002__MSBROWSE__\002") && (paramString.length() <= 15))
          {
            if (paramBoolean) {}
            for (localObject1 = lookupServerOrWorkgroup(paramString, NbtAddress.getWINSAddress());; localObject1 = NbtAddress.getByName(paramString, 0, null, NbtAddress.getWINSAddress()))
            {
              UniAddress[] arrayOfUniAddress2 = new UniAddress[1];
              arrayOfUniAddress2[0] = new UniAddress(localObject1);
              return arrayOfUniAddress2;
            }
          }
          break;
        case 1: 
          if (paramString.length() > 15)
          {
            localObject2 = localObject1;
          }
          else
          {
            Vector localVector = App.getBroadcastAdrresses();
            int k = 0;
            for (;;)
            {
              int m = localVector.size();
              if ((k >= m) || (paramBoolean)) {}
              for (;;)
              {
                try
                {
                  NbtAddress localNbtAddress2 = lookupServerOrWorkgroup(paramString, (InetAddress)localVector.get(k));
                  localObject3 = localNbtAddress2;
                  localObject1 = localObject3;
                  if (localObject1 != null) {
                    break;
                  }
                  throw new UnknownHostException(paramString);
                }
                catch (UnknownHostException localUnknownHostException)
                {
                  Object localObject3;
                  NbtAddress localNbtAddress1;
                  k++;
                }
                localNbtAddress1 = NbtAddress.getByName(paramString, 0, null, (InetAddress)localVector.get(k));
                localObject3 = localNbtAddress1;
              }
            }
          }
          break;
        case 2: 
          if (isAllDigits(paramString)) {
            throw new UnknownHostException(paramString);
          }
          InetAddress[] arrayOfInetAddress = InetAddress.getAllByName(paramString);
          arrayOfUniAddress1 = new UniAddress[arrayOfInetAddress.length];
          for (int j = 0; j < arrayOfInetAddress.length; j++) {
            arrayOfUniAddress1[j] = new UniAddress(arrayOfInetAddress[j]);
          }
          throw new UnknownHostException(paramString);
        }
      }
      catch (IOException localIOException)
      {
        localObject2 = localObject1;
      }
    }
    for (;;)
    {
      i++;
      localObject1 = localObject2;
      break;
      localObject2 = localObject1;
    }
  }
  
  static UniAddress getByName(String paramString)
    throws UnknownHostException
  {
    return getByName(paramString, false);
  }
  
  private static UniAddress getByName(String paramString, boolean paramBoolean)
    throws UnknownHostException
  {
    return getAllByName(paramString, paramBoolean)[0];
  }
  
  private static boolean isAllDigits(String paramString)
  {
    for (int i = 0; i < paramString.length(); i++) {
      if (!Character.isDigit(paramString.charAt(i))) {
        return false;
      }
    }
    return true;
  }
  
  private static boolean isDotQuadIP(String paramString)
  {
    boolean bool1 = Character.isDigit(paramString.charAt(0));
    boolean bool2 = false;
    int i;
    int j;
    char[] arrayOfChar;
    int k;
    if (bool1)
    {
      i = 0;
      j = paramString.length();
      arrayOfChar = paramString.toCharArray();
      k = 0;
    }
    for (;;)
    {
      bool2 = false;
      int m;
      if (k < j)
      {
        m = k + 1;
        boolean bool3 = Character.isDigit(arrayOfChar[k]);
        bool2 = false;
        if (bool3)
        {
          if ((m != j) || (i != 3)) {
            break label80;
          }
          bool2 = true;
        }
      }
      return bool2;
      label80:
      if ((m < j) && (arrayOfChar[m] == '.'))
      {
        i++;
        k = m + 1;
      }
      else
      {
        k = m;
      }
    }
  }
  
  /* Error */
  private static NbtAddress lookupServerOrWorkgroup(String paramString, InetAddress paramInetAddress)
    throws UnknownHostException
  {
    // Byte code:
    //   0: new 117	com/dynamixsoftware/printershare/smb/UniAddress$Sem
    //   3: dup
    //   4: iconst_2
    //   5: aconst_null
    //   6: invokespecial 120	com/dynamixsoftware/printershare/smb/UniAddress$Sem:<init>	(ILcom/dynamixsoftware/printershare/smb/UniAddress$1;)V
    //   9: astore_2
    //   10: aload_1
    //   11: invokestatic 124	com/dynamixsoftware/printershare/smb/netbios/NbtAddress:isWINS	(Ljava/net/InetAddress;)Z
    //   14: ifeq +108 -> 122
    //   17: bipush 27
    //   19: istore_3
    //   20: new 126	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread
    //   23: dup
    //   24: aload_2
    //   25: aload_0
    //   26: iload_3
    //   27: aconst_null
    //   28: aload_1
    //   29: aconst_null
    //   30: invokespecial 129	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:<init>	(Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;Ljava/lang/String;ILjava/lang/String;Ljava/net/InetAddress;Lcom/dynamixsoftware/printershare/smb/UniAddress$1;)V
    //   33: astore 4
    //   35: new 126	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread
    //   38: dup
    //   39: aload_2
    //   40: aload_0
    //   41: iconst_0
    //   42: aconst_null
    //   43: aload_1
    //   44: aconst_null
    //   45: invokespecial 129	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:<init>	(Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;Ljava/lang/String;ILjava/lang/String;Ljava/net/InetAddress;Lcom/dynamixsoftware/printershare/smb/UniAddress$1;)V
    //   48: astore 5
    //   50: aload 4
    //   52: iconst_1
    //   53: invokevirtual 133	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:setDaemon	(Z)V
    //   56: aload 5
    //   58: iconst_1
    //   59: invokevirtual 133	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:setDaemon	(Z)V
    //   62: aload_2
    //   63: monitorenter
    //   64: aload 4
    //   66: invokevirtual 136	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:start	()V
    //   69: aload 5
    //   71: invokevirtual 136	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:start	()V
    //   74: aload_2
    //   75: invokestatic 140	com/dynamixsoftware/printershare/smb/UniAddress$Sem:access$000	(Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;)I
    //   78: ifle +50 -> 128
    //   81: aload 4
    //   83: invokestatic 144	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:access$300	(Lcom/dynamixsoftware/printershare/smb/UniAddress$QueryThread;)Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
    //   86: ifnonnull +42 -> 128
    //   89: aload 5
    //   91: invokestatic 144	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:access$300	(Lcom/dynamixsoftware/printershare/smb/UniAddress$QueryThread;)Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
    //   94: ifnonnull +34 -> 128
    //   97: aload_2
    //   98: invokevirtual 147	java/lang/Object:wait	()V
    //   101: goto -27 -> 74
    //   104: astore 7
    //   106: aload_2
    //   107: monitorexit
    //   108: aload 7
    //   110: athrow
    //   111: astore 6
    //   113: new 39	java/net/UnknownHostException
    //   116: dup
    //   117: aload_0
    //   118: invokespecial 61	java/net/UnknownHostException:<init>	(Ljava/lang/String;)V
    //   121: athrow
    //   122: bipush 29
    //   124: istore_3
    //   125: goto -105 -> 20
    //   128: aload_2
    //   129: monitorexit
    //   130: aload 4
    //   132: invokestatic 144	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:access$300	(Lcom/dynamixsoftware/printershare/smb/UniAddress$QueryThread;)Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
    //   135: ifnull +9 -> 144
    //   138: aload 4
    //   140: invokestatic 144	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:access$300	(Lcom/dynamixsoftware/printershare/smb/UniAddress$QueryThread;)Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
    //   143: areturn
    //   144: aload 5
    //   146: invokestatic 144	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:access$300	(Lcom/dynamixsoftware/printershare/smb/UniAddress$QueryThread;)Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
    //   149: ifnull +9 -> 158
    //   152: aload 5
    //   154: invokestatic 144	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:access$300	(Lcom/dynamixsoftware/printershare/smb/UniAddress$QueryThread;)Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
    //   157: areturn
    //   158: aload 4
    //   160: invokestatic 151	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:access$400	(Lcom/dynamixsoftware/printershare/smb/UniAddress$QueryThread;)Ljava/net/UnknownHostException;
    //   163: athrow
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	164	0	paramString	String
    //   0	164	1	paramInetAddress	InetAddress
    //   9	120	2	localSem	Sem
    //   19	106	3	i	int
    //   33	126	4	localQueryThread1	QueryThread
    //   48	105	5	localQueryThread2	QueryThread
    //   111	1	6	localInterruptedException	java.lang.InterruptedException
    //   104	5	7	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   64	74	104	finally
    //   74	101	104	finally
    //   106	108	104	finally
    //   128	130	104	finally
    //   62	64	111	java/lang/InterruptedException
    //   108	111	111	java/lang/InterruptedException
  }
  
  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof UniAddress)) && (this.addr.equals(((UniAddress)paramObject).addr));
  }
  
  String firstCalledName()
  {
    if ((this.addr instanceof NbtAddress)) {
      return ((NbtAddress)this.addr).firstCalledName();
    }
    this.calledName = ((InetAddress)this.addr).getHostName();
    if (isDotQuadIP(this.calledName)) {
      this.calledName = "*SMBSERVER     ";
    }
    for (;;)
    {
      return this.calledName;
      int i = this.calledName.indexOf('.');
      if ((i > 1) && (i < 15)) {
        this.calledName = this.calledName.substring(0, i).toUpperCase();
      } else if (this.calledName.length() > 15) {
        this.calledName = "*SMBSERVER     ";
      } else {
        this.calledName = this.calledName.toUpperCase();
      }
    }
  }
  
  public Object getAddress()
  {
    return this.addr;
  }
  
  public String getHostAddress()
  {
    if ((this.addr instanceof NbtAddress)) {
      return ((NbtAddress)this.addr).getHostAddress();
    }
    return ((InetAddress)this.addr).getHostAddress();
  }
  
  public String getHostName()
  {
    if ((this.addr instanceof NbtAddress)) {
      return ((NbtAddress)this.addr).getHostName();
    }
    return ((InetAddress)this.addr).getHostName();
  }
  
  public int hashCode()
  {
    return this.addr.hashCode();
  }
  
  String nextCalledName()
  {
    if ((this.addr instanceof NbtAddress)) {
      return ((NbtAddress)this.addr).nextCalledName();
    }
    if (this.calledName != "*SMBSERVER     ")
    {
      this.calledName = "*SMBSERVER     ";
      return this.calledName;
    }
    return null;
  }
  
  public String toString()
  {
    return this.addr.toString();
  }
  
  private static class QueryThread
    extends Thread
  {
    private NbtAddress ans = null;
    private String host;
    private String scope;
    private UniAddress.Sem sem;
    private InetAddress svr;
    private int type;
    private UnknownHostException uhe;
    
    private QueryThread(UniAddress.Sem paramSem, String paramString1, int paramInt, String paramString2, InetAddress paramInetAddress)
    {
      super();
      this.sem = paramSem;
      this.host = paramString1;
      this.type = paramInt;
      this.scope = paramString2;
      this.svr = paramInetAddress;
    }
    
    /* Error */
    public void run()
    {
      // Byte code:
      //   0: aload_0
      //   1: aload_0
      //   2: getfield 43	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:host	Ljava/lang/String;
      //   5: aload_0
      //   6: getfield 45	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:type	I
      //   9: aload_0
      //   10: getfield 47	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:scope	Ljava/lang/String;
      //   13: aload_0
      //   14: getfield 49	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:svr	Ljava/net/InetAddress;
      //   17: invokestatic 69	com/dynamixsoftware/printershare/smb/netbios/NbtAddress:getByName	(Ljava/lang/String;ILjava/lang/String;Ljava/net/InetAddress;)Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
      //   20: putfield 39	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:ans	Lcom/dynamixsoftware/printershare/smb/netbios/NbtAddress;
      //   23: aload_0
      //   24: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   27: astore 13
      //   29: aload 13
      //   31: monitorenter
      //   32: aload_0
      //   33: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   36: invokestatic 75	com/dynamixsoftware/printershare/smb/UniAddress$Sem:access$010	(Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;)I
      //   39: pop
      //   40: aload_0
      //   41: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   44: invokevirtual 80	java/lang/Object:notify	()V
      //   47: aload 13
      //   49: monitorexit
      //   50: return
      //   51: astore 9
      //   53: aload_0
      //   54: aload 9
      //   56: putfield 58	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:uhe	Ljava/net/UnknownHostException;
      //   59: aload_0
      //   60: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   63: astore 10
      //   65: aload 10
      //   67: monitorenter
      //   68: aload_0
      //   69: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   72: invokestatic 75	com/dynamixsoftware/printershare/smb/UniAddress$Sem:access$010	(Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;)I
      //   75: pop
      //   76: aload_0
      //   77: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   80: invokevirtual 80	java/lang/Object:notify	()V
      //   83: aload 10
      //   85: monitorexit
      //   86: return
      //   87: astore 11
      //   89: aload 10
      //   91: monitorexit
      //   92: aload 11
      //   94: athrow
      //   95: astore 5
      //   97: aload_0
      //   98: new 61	java/net/UnknownHostException
      //   101: dup
      //   102: aload 5
      //   104: invokevirtual 83	java/lang/Exception:getMessage	()Ljava/lang/String;
      //   107: invokespecial 84	java/net/UnknownHostException:<init>	(Ljava/lang/String;)V
      //   110: putfield 58	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:uhe	Ljava/net/UnknownHostException;
      //   113: aload_0
      //   114: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   117: astore 6
      //   119: aload 6
      //   121: monitorenter
      //   122: aload_0
      //   123: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   126: invokestatic 75	com/dynamixsoftware/printershare/smb/UniAddress$Sem:access$010	(Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;)I
      //   129: pop
      //   130: aload_0
      //   131: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   134: invokevirtual 80	java/lang/Object:notify	()V
      //   137: aload 6
      //   139: monitorexit
      //   140: return
      //   141: astore 7
      //   143: aload 6
      //   145: monitorexit
      //   146: aload 7
      //   148: athrow
      //   149: astore_1
      //   150: aload_0
      //   151: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   154: astore_2
      //   155: aload_2
      //   156: monitorenter
      //   157: aload_0
      //   158: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   161: invokestatic 75	com/dynamixsoftware/printershare/smb/UniAddress$Sem:access$010	(Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;)I
      //   164: pop
      //   165: aload_0
      //   166: getfield 41	com/dynamixsoftware/printershare/smb/UniAddress$QueryThread:sem	Lcom/dynamixsoftware/printershare/smb/UniAddress$Sem;
      //   169: invokevirtual 80	java/lang/Object:notify	()V
      //   172: aload_2
      //   173: monitorexit
      //   174: aload_1
      //   175: athrow
      //   176: astore_3
      //   177: aload_2
      //   178: monitorexit
      //   179: aload_3
      //   180: athrow
      //   181: astore 14
      //   183: aload 13
      //   185: monitorexit
      //   186: aload 14
      //   188: athrow
      // Local variable table:
      //   start	length	slot	name	signature
      //   0	189	0	this	QueryThread
      //   149	26	1	localObject1	Object
      //   154	24	2	localSem1	UniAddress.Sem
      //   176	4	3	localObject2	Object
      //   95	8	5	localException	java.lang.Exception
      //   117	27	6	localSem2	UniAddress.Sem
      //   141	6	7	localObject3	Object
      //   51	4	9	localUnknownHostException	UnknownHostException
      //   63	27	10	localSem3	UniAddress.Sem
      //   87	6	11	localObject4	Object
      //   27	157	13	localSem4	UniAddress.Sem
      //   181	6	14	localObject5	Object
      // Exception table:
      //   from	to	target	type
      //   0	23	51	java/net/UnknownHostException
      //   68	86	87	finally
      //   89	92	87	finally
      //   0	23	95	java/lang/Exception
      //   122	140	141	finally
      //   143	146	141	finally
      //   0	23	149	finally
      //   53	59	149	finally
      //   97	113	149	finally
      //   157	174	176	finally
      //   177	179	176	finally
      //   32	50	181	finally
      //   183	186	181	finally
    }
  }
  
  private static class Sem
  {
    private int count;
    
    private Sem(int paramInt)
    {
      this.count = paramInt;
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.smb.UniAddress
 * JD-Core Version:    0.7.0.1
 */